<template>
	<view class="u-page">
		<view class="header">

		</view>
		<view class="content">
			<view class="u-page__item" v-if="auth == true">
				<!-- 判断是否授权 -->

				<view class="user_group">

					<view class="demo-layout bg-purple">
						<image :src="userData.avatarUrl" mode=""></image>
					</view>
					<view class="demo-layout bg-purple-light two" @click="goPage('/pages/user/userinfo',true)">
						<view class="title">{{userData.nickname}}</view>
						<view class="titleinfo">个人资料</view>
					</view>
					<view class="demo-layout bg-purple-dark three" @click="goPage('/pages/user/message/message',true)" style="height: 50px;">
						<image src="../../static/icon/user/message.png" mode="" style="width: 28px;height: 28px;">
						</image>
					</view>
				</view>
				<!-- 没有授权 -->
			</view>
			<view class="u-page__item" v-else>
				<uni-row class="demo-uni-row">
					<uni-col :span='7'>
						<view class="demo-layout bg-purple">
							<image src="../../static/icon/userpic.png" mode=""></image>
						</view>
					</uni-col>
					<uni-col :span='12'>
						<view class="demo-layout bg-purple-light" @click="goPage('/pages/user/login',true)">
							<view class="title">去授权</view>
							<view>请授权获取的你的信息。</view>
						</view>
					</uni-col>
				</uni-row>
			</view>

			<view class="vipCard" v-if="invemt.length > 0">
				<uni-swiper-dot :info="list" :current="current" field="content" mode="default">
					<swiper :autoplay="autoplay" class="swiper-box" style="height: 118px;">
						<swiper-item v-for="(item ,index) in invemt" :key="index">
							<view class="userlevel">
								<view class="level">{{item.slProjectByPid.title}}</view>
								<view class="usertype" v-if="item.level =='1'">{{familyname}}</view>
								<view class="usertype" v-if="item.level =='2'">投资人</view>
								<view class="usertype" v-if="item.level =='3'">股东</view>
								<!-- <view class="usertype">{{item.slProjectByPid.title}}</view> -->
							</view>
							<view class="levelrule">
								{{item.slProjectByPid.familyRights}}
							</view>
							<view class="vipBg">
								<image src="../../static/icon/user/viplevel.png" mode=""></image>
							</view>
						</swiper-item>
					</swiper>
				</uni-swiper-dot>
			</view>
			<view class="vipCard" v-if="auth == true && invemt.length == 0">
				<view class="userlevel">
					<view class="level">普通用户</view>
					<view class="usertype">当前用户类型</view>
					<view class="userinfo">详情</view>
				</view>
				<view class="levelinfo">平台家人享有上架项目通用权益及任务奖励</view>
				<view class="levelrule">
					<view>1、线下实体店订单奖励、消费金额奖励</view>
					<view>2、线上外卖订单奖励、消费金额奖励</view>
				</view>
				<view class="vipBg">
					<image src="../../static/icon/user/viplevel.png" mode=""></image>
				</view>
			</view>
			<view class="money" v-if="invemt.length > 0">
				<uni-row class="userwallet">
					<uni-col :span='12'>
						<view class="wallet" @click="goPage('/pages/user/wallet/wallet',true)">
							<view class="icon">
								<image src="../../static/icon/user/money.png" mode=""></image>
							</view>
							<view class="balance">
								<view class="title">我的余额</view>
								<view class="titleinfo">￥{{userData.balance + userData.wallet}}</view>
							</view>
						</view>

					</uni-col>
					<uni-col :span='12'>
						<view class="wallet" @click="goPage('/pages/user/wallet/task',true)">
							<view class="icon">
								<image src="../../static/icon/user/task.png" mode=""></image>
							</view>
							<view class="balance">
								<view class="title">任务大厅</view>
								<view class="titleinfo">新发布0个任务</view>
							</view>
						</view>
					</uni-col>
				</uni-row>
			</view>
			<view class="jiange">
				<uni-row class="demo-uni-row">
					<uni-col :span='12'>
						<view class="remen">我投资的项目</view>
					</uni-col>
					<uni-col :span='12'>
						<view class="more" @click="goPage('/pages/user/project/myinvestment',true)">全部项目 <image
								src="../../static/icon/more.png" mode=""></image>
						</view>
					</uni-col>
				</uni-row>
				<view class="projectList" v-if="invemt.length > 0">
					<block v-for="(item, index) in invemt" :key="item.pid">
						<view class="lists" @click="goPage('/pages/user/userProject?id='+item.pid,true)">
							<view class="images">
								<image :src="item.slProjectByPid.pic" mode="scaleToFill"></image>
							</view>
							<view class="list_contnet">
								<view class="projecttitle">{{item.slProjectByPid.title}}</view>
								<view class="projectinfo"> {{item.slProjectByPid.contentInfo}}</view>
								<view class="tags">
									<block v-for="(tag,index1) in item.slProjectByPid.tag" :key='index1'>
										<uni-tag class="tag" :inverted="true" size="small" :text="tag" type="primary"
											circle="true"></uni-tag>
									</block>
								</view>
							</view>

						</view>
					</block>
				</view>
				<view class="projectList" v-else>
					<view class="lable">你还没有参加投资项目。</view>
				</view>
			</view>
			<view class="jiange">
				<uni-row class="demo-uni-row">
					<uni-col :span='12'>
						<view class="remen">我发起的项目</view>
					</uni-col>
					<uni-col :span='12'>
						<view class="more" @click="goPage('/pages/user/project/mylaunch',true)">全部项目 <image
								src="../../static/icon/more.png" mode=""></image>
						</view>
					</uni-col>
				</uni-row>
				<view class="projectList" v-if="lists.length > 0">
					<block v-for="(item, index) in lists" :key="item.pid">
						<view class="lists" @click="goPage('/pages/user/project/myProject?id='+item.pid,true)">
							<view class="images">
								<image :src="item.pic" mode=""></image>
							</view>
							<view class="list_contnet">
								<view class="projecttitle">{{item.title}}</view>
								<view class="projectinfo"> {{item.contentInfo}}</view>
								<view class="tags">
									<block v-for="(tag,index1) in item.tag" :key='index1'>
										<uni-tag class="tag" :text="tag" type="primary" circle="true"></uni-tag>
									</block>
								</view>
							</view>

						</view>
					</block>
				</view>
				<view class="projectList" v-else>
					<view class="lable">你还没有创建项目。</view>
				</view>
			</view>

			<view class="plate credit">
				<view class="title">信用服务</view>
				<view class="projectCell">
					<view class="cell-item" @click="goPage('/pages/user/userinfo/idcard',true)" v-if="userData.idAttestation ==1">
					
						<image src="http://file.lsdjk.net/shiliu/identity.png" mode="scaleToFill">
						</image>
						<text class="cell-item-shenfen">身份认证</text>
						<image
							:src="[userData.idAttestation==1?'../../static/icon/user/renzheng.png':'../../static/icon/user/weirenzheng.png']"
							mode="scaleToFill"></image>
						<text class="cell-item-span">{{userData.idAttestation==1?'已认证':'未认证'}}</text>
						<uni-icons type="forward" size="18" color="#818181"></uni-icons>
					</view>
					<view class="cell-item" @click="goPage('/pages/project/investment/authentication',true)" v-else>
						<image src="http://file.lsdjk.net/shiliu/identity.png" mode="scaleToFill">
						</image>
						<text class="cell-item-shenfen">身份认证</text>
						<image
							:src="[userData.idAttestation==1?'../../static/icon/user/renzheng.png':'../../static/icon/user/weirenzheng.png']"
							mode="scaleToFill"></image>
						<text class="cell-item-span">{{userData.idAttestation==1?'已认证':'未认证'}}</text>
						<uni-icons type="forward" size="18" color="#818181"></uni-icons>
					</view>

					<view class="cell-item" @click="goPage('/pages/user/userinfo/idcard',userData.phoneAttestation==1)">
						<image src="http://file.lsdjk.net/shiliu/identity.png" mode="scaleToFill">
						</image>
						<text class="cell-item-shenfen">电话卡实名认证</text>
						<image
							:src="[userData.phoneAttestation==1?'../../static/icon/user/renzheng.png':'../../static/icon/user/weirenzheng.png']"
							mode="scaleToFill"></image>
						<text class="cell-item-span">{{userData.phoneAttestation==1?'已认证':'未认证'}}</text>
						<uni-icons type="forward" size="18" color="#818181"></uni-icons>
					</view>
					
					<view class="cell-item" @click="goPage('/pages/user/userinfo/phoneAuth',userData.phoneLssue)">
						<image src="http://file.lsdjk.net/shiliu/identity.png" mode="scaleToFill">
						</image>
						<text class="cell-item-shenfen">电话卡归属地</text>
						<image
							:src="[userData.phoneLssue?'../../static/icon/user/renzheng.png':'../../static/icon/user/weirenzheng.png']"
							mode="scaleToFill"></image>
						<text class="cell-item-span">{{userData.phoneLssue?'已查询':'未查询'}}</text>
						<uni-icons type="forward" size="18" color="#818181"></uni-icons>
					</view>

			
				</view>
			</view>

			<view class="plate credit">
				<view class="title">收藏&浏览记录</view>
				<view class="projectCell">
					
					<view class="cell-item" @click="goPage('/pages/user/record?type=1',true)">
						<image src="http://file.lsdjk.net/shiliu/Collection.png" mode="scaleToFill">
						</image>
						<text class="cell-item-shenfen">我的收藏</text>
						<uni-icons type="forward" size="18" color="#818181"></uni-icons>
					</view>
					
					<view class="cell-item" @click="goPage('/pages/user/record?type=2',true)">
						<image src="http://file.lsdjk.net/shiliu/browse.png" mode="scaleToFill">
						</image>
						<text class="cell-item-shenfen">浏览记录</text>
						<uni-icons type="forward" size="18" color="#818181"></uni-icons>
					</view>
		
				</view>
			</view>
			<view class="store" v-if="userData.isStore ==1">
				<view class="stotrImg">
					<image src="../../static/icon/user/store.png" mode=""></image>
				</view>
				<view class="storeTitle">商家端入口</view>
				<view class="storeBut">
					<button type="warn" size="mini" @click="goPage('/pages/store/storeindex',true)">立即进入</button>
				</view>
			</view>
			<view class="plate credit">
				<view class="title">关于我们</view>
				<view class="projectCell">
					<view class="cell-item">
						<image src="http://file.lsdjk.net/shiliu/edition.png" mode="scaleToFill">
						</image>
						<text class="cell-item-shenfen">版本信息</text>
						<!-- <uni-icons type="forward" size="18" color="#818181"></uni-icons> -->
						<text style="color: #949494;font-size:14px;">V1.0</text>
					</view>
					<view class="cell-item" @click="goPage('/pages/user/feedback',true)">
						<image src="http://file.lsdjk.net/shiliu/opinion.png" mode="scaleToFill">
						</image>
						<text class="cell-item-shenfen">意见反馈</text>
						<uni-icons type="forward" size="18" color="#818181"></uni-icons>
					</view>
					<view class="cell-item">
						<image src="http://file.lsdjk.net/shiliu/system.png" mode="scaleToFill">
						</image>
						<text class="cell-item-shenfen">系统设置</text>
						<uni-icons type="forward" size="18" color="#818181"></uni-icons>
					</view>
			
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				auth: false,
				userData: {},
				user:{},
				border: false,
				info: '11111',
				lists: [],
				invemt: [],
				familyname: '',
				userpid:[],
			}
		},
		async onShow() {
			let user = uni.getStorageSync('userData');
			if (user != '') {
				this.auth = true
				this.user = user;
				this.userInfo()
				this.project()
				this.usertask()

			} else {
				this.auth = false
			}

		},
		methods: {
			//获取我的项目任务
			async usertask(){
				// console.log('1---',this.userpid)
				
				// const user = await this.GQL({
				// 	"operationName": "allSlProjectStoreTasks",
				// 	"query": "query allSlProjectStoreTasks($filter: SlProjectStoreTaskFilter) { allSlProjectStoreTasks(filter:$filter) { totalCount } }",
				// 	"variables": {
				// 		"filter": {
				// 			"pid": {
				// 				"in": this.user.uid
				// 			}
				// 		}
				// 	}
				// })
				
				
			},
			//获取个人信息
			async userInfo() {
				const user = await this.GQL({
					"operationName": "allSlUsers",
					"query": "query allSlUsers($filter: SlUserFilter) { allSlUsers(filter:$filter) { nodes { phoneAttestation idAttestation phone openid nickname level jurisdiction isStore uid status storeBalance balance avatarUrl phoneLssue wallet } } }",
					"variables": {
						"filter": {
							"uid": {
								"equalTo": this.user.uid
							}
						}
					}
				})
				// console.log('1----', user.data.allSlUsers.nodes[0])
				this.userData = user.data.allSlUsers.nodes[0]
			},
			async project() {
				//我创建的
				const project1 = await this.GQL({
					"operationName": "allSlProjects",
					"query": "query allSlProjects($filter: SlProjectFilter) { allSlProjects(filter: $filter) { nodes { title type tag status pic pid contentInfo uuid } } }",
					"variables": {
						"filter": {
							"status": {
								"equalTo": "1"
							},
							"uuid": {
								"equalTo": this.user.uid
							}
						}
					}
				})
				if (project1.data.allSlProjects.node != '') {
					project1.data.allSlProjects.nodes.forEach(function(item, index) {
						if (item.tag) {
							item.tag = item.tag.split(',')
						}
					});
					this.lists = project1.data.allSlProjects.nodes
				}
				const familyname = await this.GQL({
					"operationName": "allSlSystemConfigs",
					"query": "query allSlSystemConfigs($filter: SlSystemConfigFilter) { allSlSystemConfigs(filter: $filter) { nodes { id  menuName familyname} } }",
					"variables": {
						"filter": {
							"menuName": {
								"equalTo": "site_name"
							}
						}
					}
				})
				if (familyname.data.allSlSystemConfigs.nodes != '') {
					this.familyname = familyname.data.allSlSystemConfigs.nodes[0].familyname
				}
				//我投资得
				const investment = await this.GQL({
					"operationName": "allSlUserProjectvips",
					"query": "query allSlUserProjectvips($filter: SlUserProjectvipFilter) { allSlUserProjectvips(filter: $filter) { nodes { vid uid level pid slProjectByPid { tag title status projectInfo contentInfo investRights pic pid familyRights } } } }",
					"variables": {
						"filter": {
							"uid": {
								"equalTo": this.user.uid,
								
							}
						}
					}
				})
				// console.log('1----',investment)
				if (investment.data.allSlUserProjectvips.nodes != '') {
					investment.data.allSlUserProjectvips.nodes.forEach(function(item, index) {
						// this.userpid[index] = item.pid
						console.log('111',this.userpid)
						if (item.slProjectByPid.tag) {
							item.slProjectByPid.tag = item.slProjectByPid.tag.split(',')
						}
					});
					this.invemt = investment.data.allSlUserProjectvips.nodes
				}
			},

			goPage(url, flag) {
				console.log(flag)
				if (flag) {
					let user = uni.getStorageSync('userData');
					if (!user) {
						uni.navigateTo({
							url: "/pages/user/login"
						})
					} else {
						uni.navigateTo({
							url: url
						})
					}
				}

			}
		}
	}
</script>

<style lang="scss">
	.u-page {

		background: #FBFCFE;
	}

	.content {
		position: relative;
		top: -200px;
		margin: 15px;

	}

	.user_group {
		display: flex;

		.two {
			flex: 1;
			margin-left: 10px;
		}


	}

	.header {
		width: 100%;
		height: 200px;
		background: linear-gradient(#C7171E, #FBFCFE);

		/* 标准的语法 */
		.nav-bar {
			.uni-navbar__header {
				padding-left: 15px;
			}

			.uni-navbar__header-btns-left {
				width: 150px;
			}

			.sitename {
				height: 50px;
				font-size: 18px;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 550;
				text-align: left;
				color: #FFFFFF;
			}
		}
	}


	.u-page__item {
		height: 80px;
		// margin-bottom: 15px;
		color: #FFFFFF;
		background-color: transparent;

		.bg-purple {
			display: flex;
			align-items: center;
			justify-content: center;
			height: 80px;

			image {
				border-radius: 50px;
			}

			border-radius: 50%;
		}

		.bg-purple image {
			width: 61px;
			height: 60px;
		}

		.bg-purple-light {
			height: 80px;
		}

		.title {
			padding-top: 18px;
			font-size: 16px;

			font-weight: 600;
		}

		.titleinfo {
			margin-top: 5px;
			font-size: 12px;
			font-weight: 400;
			background-color: #FFF4E5;
			width: 50px;
			color: #161E3E;
			padding: 2px 6px;
			border-radius: 6px;

		}

		.bg-purple-dark {
			display: flex;
			align-items: flex-end;
			height: 65px;

			image {
				width: 40px;
				height: 40px;
			}
		}
	}

	.vipCard {
		// height: 130px;
		// background-color: #FFFFFF;
		background-image: linear-gradient(to right, #FFF1DD, #EEAB77);
		border-radius: 5px;
		position: relative;

		.userlevel {
			display: flex;
			align-items: center;
			// justify-content: center;
			padding: 12px;
			text-align: center;

			.level {
				font-size: 19px;
				font-weight: 600;
				color: #A54900;
				// line-height: 16px;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			.usertype {
				margin-left: 10px;
				font-size: 10px;
				border: 1px solid #EAAE7D;
				// background-color: #EAAE7D;
				color: #975118;
				padding: 3px;
				border-radius: 10px;
			}

			.userinfo {
				position: absolute;
				right: 20px;
				font-size: 12px;
				font-weight: 400;
				color: #975118;
				line-height: 12px;
				background-color: #EAAE7D;
				padding: 5px;
				border-radius: 10px;
			}

		}

		.levelinfo {
			padding: 12px;
			font-size: 10px;
			font-weight: 500;
			color: #975118;
			line-height: 12px;
		}

		.levelrule {
			// width: 300px;
			// height: 100px;
			padding: 0px 12px;
			font-size: 10px;
			font-weight: 400;
			color: #975118;
			line-height: 16px;
			margin-bottom: 10px;
		}

		.vipBg {
			position: absolute;
			right: 0px;
			bottom: 0;

			image {
				width: 108px;
				height: 74px;
			}

		}
	}

	.money {
		height: 80px;
		background-color: #FFFFFF;
		border-radius: 10px;
		margin-top: 20px;
		color: #000000;
		box-shadow: 4px 2px 4px 6px rgba(0, 0, 0, 0.1);

		.wallet {
			height: 80px;
			display: flex;
			align-items: center;
			justify-content: center;

		}

		.balance {
			margin-left: 10px;

			.title {
				font-size: 14px;
				font-weight: 500;
				color: #161E3E;
				line-height: 16px;
				margin-bottom: 8px;
			}

			.titleinfo {
				font-size: 13px;
				font-weight: 400;
				color: #C7171E;
				line-height: 12px;

			}
		}

		image {
			width: 30px;
			height: 30px;
		}
	}

	.jiange {
		margin: 20px 0px;
		width: 100%;

		.remen {
			font-size: 18px;
			color: #161E3E;
			font-weight: bold;
		}

		.more {
			text-align: right;
			font-size: 12px;
			color: #9BA7C1;

			image {
				width: 10px;
				height: 10px;
			}
		}

		.projectList {
			.lable {
				height: 50px;
				text-align: center;
				font-size: 15px;
				font-weight: 400;
				color: #9BA7C1;
				line-height: 50px;
			}

			.lists {
				margin: 10px 0px;
				display: flex;


				.list_contnet {
					margin-left: 8px;
					display: flex;
					flex-direction: column;
					justify-content: space-around;

					.projecttitle {
						width: 100%;
						height: 16px;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						font-size: 15px;
						font-weight: 600;
						color: #161E3E;
						line-height: 16px;
					}

					.projectinfo {
						margin: 10px 0px;
						font-size: 11px;
						font-weight: 400;
						color: #9BA7C1;
						line-height: 15px;
					}

					.tags {
						// font-size: 11px;
						padding: 2px 0;

						.tag {
							margin-right: 5px;
						}
					}
				}
			}
			.images{
				display: flex;
				align-items: center;
			}

			image {
				border-radius: 6px;
				width: 90px;
				height: 90px;
			}
		}
	}

	.store {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 50px;
		background: #FFE1E2;
		border-radius: 5px;
		margin: 20px 0px;
		padding: 0 10px;

		image {
			width: 30px;
			height: 30px;
		}

		.stotrImg {
			// margin: 10px 0px 10px 10px;
			width: 40px;
		}

		.storeTitle {
			flex: 1;
			width: 120px;
			// margin: 13px;
			font-size: 15px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 600;
			color: #161E3E;
			line-height: 21px;
		}

		.storeBut {
			// margin-top: 10px;
			button{
				border-radius: 20px;
			}
		}
	}

	.plate {
		margin-bottom: 20px;
	}

	.credit {
		.title {
			font-size: 18px;
			font-weight: 600;
			color: #161E3E;
			line-height: 16px;
			margin-bottom: 20px;
		}

		.projectCell {
			.cell-item {
				display: flex;
				align-items: center;
				padding: 10px 0;
				.cell-item-shenfen {
					font-size: 14px;
					flex: 1;
					color: #161E3E;
				}

				.cell-item-span {
					font-size: 14px;
					color: #9BA7C1;
				}

				>image:nth-child(1) {
					width: 18px;
					height: 18px;
					margin-right: 8px;
				}

				>image:nth-child(3) {
					width: 14px;
					height: 14px;
					margin-right: 4px;
				}
			}


			.uni-list-item__content-title {
				font-size: 15px;
				font-weight: 400;
				color: #161E3E;
				line-height: 21px;

			}

			.uni-list,
			.uni-list-item {
				background: #FBFCFE;
			}
		}
	}
</style>
